import { getMovies, getMovie } from "../../services/mockService"
import Head from 'next/head'
import { useRouter } from "next/router"

export default ({movie}) =>{
  // console.log('movie detail render')

  const router = useRouter();
  if (router.isFallback) {
    return <h1>Loading...</h1>
  } else {
    return (<div>
      <Head>
        <title>电影详情页</title>
      </Head>
      <h1>{movie.name}</h1>
      <p>{movie.updateTime}</p>
    </div>)
  }
}

export async function getStaticProps({params}) {
  const resp = await getMovie(params.id)
  return {
    props: {
      movie: resp.data
    }
  }
}

export async function getStaticPaths() {
  console.log('getStaticPaths')
  const resp = await getMovies()
  const paths = resp.data.map(m => ({
    params: {
      id: m._id
    }
  }))
  return {
    paths,
    fallback: true // false 什么都不做 如果没有静态页面 返回404 true给[id].html
  }
}